package leetcode.leetcode_117;


class Solution {
    public Node connect(Node root) {
        if (root == null){
            return null;
        }
        Node dummy = new Node();
        Node curr = root;
        while(curr != null){
            dummy.next = null;
            Node next = dummy;// 用来存储下一层的节点
            while(curr!=null){
                if (curr.left!=null){
                    next.next = curr.left;
                    next = next.next;
                }
                if (curr.right!=null){
                    next.next = curr.right;
                    next = next.next;
                }
                curr = curr.next;
            }
            curr = dummy.next;
        }
        return root;
    }
}